//
//  ViewController.swift
//  CheckPath
//
//  Created by 王渊鸥 on 2018/10/20.
//  Copyright © 2018 WangYuanOu. All rights reserved.
//

import UIKit
import ExDraw

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        showPath()
    }

    func showPath() {
        let text = "$0&20.0%20.0$1&200.0%200.0$1&100.0%100.0$2&20.0%20.0&10.0%10.0$4"
        let path = CGPath.from(text: text)
        
        path.applyWithBlock { (pt) in
            switch pt.pointee.type {
            case .moveToPoint:
                let point = pt.pointee.points[0]
                print("move to x:\(point.x) y:\(point.y)")
            case .addLineToPoint:
                let point = pt.pointee.points[0]
                print("add line to x:\(point.x) y:\(point.y)")
            case .addQuadCurveToPoint:
                let contrl = pt.pointee.points[0]
                let point = pt.pointee.points[1]
                print("add quad curve line to x:\(point.x) y:\(point.y) by control x:\(contrl.x) y:\(contrl.y)")
            case .addCurveToPoint:
                let contrl1 = pt.pointee.points[0]
                let contrl2 = pt.pointee.points[1]
                let point = pt.pointee.points[2]
                print("add curve line to x:\(point.x) y:\(point.y) by control1 x:\(contrl1.x) y:\(contrl1.y), control2 x:\(contrl2.x) y:\(contrl2.y)")
            case .closeSubpath:
                print("close sub path")
            }
        }
    }
}

